package com.yanqu.road.server.gameplayer.module.activity.horserun.event;

import com.yanqu.road.entity.activity.horserun.HorseRunUserGamingData;
import com.yanqu.road.entity.activity.horserun.config.HorseRunEventConfig;
import com.yanqu.road.logic.activity.horserun.HorseRunConfig;
import com.yanqu.road.pb.activity.HorseRunProto;

import java.util.ArrayList;
import java.util.List;

/**
 *     addConfident("信心值回复",5),
 */
public class HorseRunAddConfidentEvent extends HorseRunBaseEvent {

    @Override
    public HorseRunProto.EventResult.Builder meet(HorseRunUserGamingData userGamingData, HorseRunConfig config, HorseRunEventConfig eventConfigById) {
        HorseRunProto.EventResult.Builder builder = HorseRunProto.EventResult.newBuilder();
        int eventId = eventConfigById.getId();
        builder.setError(0);

        addUserLog(userGamingData,config,1,eventId,new ArrayList<>(),builder);
        eventGoing(userGamingData);

        return builder;
    }

    @Override
    public HorseRunProto.EventResult.Builder deal(HorseRunUserGamingData userGamingData, HorseRunDealEventArg arg, HorseRunConfig config, HorseRunEventConfig eventConfigById) {
        HorseRunProto.EventResult.Builder builder = HorseRunProto.EventResult.newBuilder();
        int eventId = eventConfigById.getId();

        int addConfidentNum = eventConfigById.getParamList().get(0);

        builder.setError(0);
        if (userGamingData.getNowConfident() + addConfidentNum >= userGamingData.getMaxConfident()) {
            addConfidentNum = userGamingData.getMaxConfident() - userGamingData.getNowConfident();
        }

        userGamingData.setNowConfident(userGamingData.getNowConfident() + addConfidentNum);
        builder.setAddConfident(addConfidentNum);

        List<Integer>logParam = new ArrayList<Integer>();
        logParam.add(addConfidentNum);

        addUserLog(userGamingData,config,2,eventId,logParam,builder);
        eventDone(userGamingData);
        return builder;
    }
}
